package com.example.spinning.service;

import com.example.spinning.bean.SpinningQualityReport;
import com.example.spinning.mapper.SpinningQualityReportMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.spinning.bean.PaginationResult;

import java.sql.Date;
import java.util.List;
@Service
@Transactional
public class SpinningQualityReportService {
    @Autowired
    SpinningQualityReportMapper spinningQualityReportMapper;


    //增加操作
    public int addNewSpinningQualityReport(SpinningQualityReport spinningQualityReport) {
        return spinningQualityReportMapper.addNewSpinningQualityReport(spinningQualityReport);
    }

    //删除操作
    public boolean deleteSpinningQualityReportById(Long[] ids) {
        int result = spinningQualityReportMapper.deleteSpinningQualityReportById(ids);
        return result == ids.length;
    }

    public PaginationResult<SpinningQualityReport> findPage(Integer page, Integer size, String batch_no, String name, String client, Date date,String color) {

        QueryWrapper<SpinningQualityReport> wrapper = new QueryWrapper();
        if(null!=batch_no)
            wrapper.eq("batch_no",batch_no);
        if (null!=name)
            wrapper.eq("name", name);
        if (null!=client)
            wrapper.eq("client", client);
        if (null!=date)
            wrapper.eq("date", date);
        if(null!=color)
            wrapper.eq("color",color);


        Page<SpinningQualityReport> pages = new Page<>(page,size);
        spinningQualityReportMapper.selectPage(pages, wrapper);
        int total = spinningQualityReportMapper.selectCount(wrapper);
        List<SpinningQualityReport> list = pages.getRecords();

        PaginationResult<SpinningQualityReport> pr = new PaginationResult<>();
        pr.setTotal(total);
        pr.setList(list);
        return pr;
    }
    //动态修改
    public int updateCategoryById(SpinningQualityReport spinningQualityReport){
        int result = spinningQualityReportMapper.updateById(spinningQualityReport);
        return result;
    }



}
